/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package org.eclipse.iota.model;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.util.EObjectResolvingEList;
import org.eclipse.iota.IotaPackage;

/**
 * @see org.eclipse.iota.IotaPackage#getInclusion()
 * @model kind="class"
 * @generated
 */
public class Inclusion extends Constraint {

	/**
	 * @generated NOT
	 * @param target Target property.
	 */
	public Inclusion(Property target) {
		super();
		setTarget(target);
	}

	/**
	 * @generated NOT
	 */
	@Override
	public boolean isTrue() {
		return false;
	}

	/**
	 * @generated NOT
	 */
	@Override
	public boolean isFalse() {
		return false;
	}
	
	/**
	 * Check if this inclusion constitutes a recursion.
	 * @return <code>true</code> if it is a recursion.
	 * @generated NOT
	 */
	public boolean isRecursion() {
		return (getClause()!=null && 
				getClause().getAlternation()!=null &&
				getClause().getAlternation().getDefinition()==target &&
				getArguments().size()==getClause().getAlternation().getDefinition().getParameters().size());
	}

	/**
	 * @generated NOT
	 */
	@Override
	public String toString() {
		String name = (getTarget()==null) ? "null" : getTarget().getName();
		StringBuffer result = new StringBuffer(name + "(");
		for (int i=0; i<getArguments().size(); i++) {
			result.append(getArguments().get(i));
			if (i<getArguments().size()-1) result.append(",");
		}
		return result + ")";
	}

	/* ---------------------------------------------------------------- *
	 * GENERATED CODE.                                                  *
	 * Do not edit below this line. If you need to edit, move it above  *
	 * this line and change the '@generated'-tag to '@generated NOT'.   *
	 * ---------------------------------------------------------------- */	

	/**
	 * The cached value of the '{@link #getTarget() <em>Target</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTarget()
	 * @generated
	 * @ordered
	 */
	protected Property target;

	/**
	 * The cached value of the '{@link #getArguments() <em>Arguments</em>}' reference list.
	 * @see #getArguments()
	 * @generated
	 * @ordered
	 */
	protected EList<Variable> arguments;

	/**
	 * @generated
	 */
	public Inclusion() {
		super();
	}

	/**
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return IotaPackage.Literals.INCLUSION;
	}

	/**
	 * Returns the value of the '<em><b>Target</b></em>' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @return the value of the '<em>Target</em>' reference.
	 * @see #setTarget(Property)
	 * @see org.eclipse.iota.IotaPackage#getInclusion_Target()
	 * @model
	 * @generated
	 */
	public Property getTarget() {
		if (target != null && target.eIsProxy()) {
			InternalEObject oldTarget = (InternalEObject)target;
			target = (Property)eResolveProxy(oldTarget);
			if (target != oldTarget) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, IotaPackage.INCLUSION__TARGET, oldTarget, target));
			}
		}
		return target;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Property basicGetTarget() {
		return target;
	}

	/**
	 * Sets the value of the '{@link org.eclipse.iota.model.Inclusion#getTarget <em>Target</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @param value the new value of the '<em>Target</em>' reference.
	 * @see #getTarget()
	 * @generated
	 */
	public void setTarget(Property newTarget) {
		Property oldTarget = target;
		target = newTarget;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, IotaPackage.INCLUSION__TARGET, oldTarget, target));
	}

	/**
	 * Returns the value of the '<em><b>Arguments</b></em>' reference list.
	 * The list contents are of type {@link org.eclipse.iota.model.Variable}.
	 * @return the value of the '<em>Arguments</em>' reference list.
	 * @see org.eclipse.iota.IotaPackage#getInclusion_Arguments()
	 * @model
	 * @generated
	 */
	public EList<Variable> getArguments() {
		if (arguments == null) {
			arguments = new EObjectResolvingEList<Variable>(Variable.class, this, IotaPackage.INCLUSION__ARGUMENTS);
		}
		return arguments;
	}

	/**
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case IotaPackage.INCLUSION__TARGET:
				if (resolve) return getTarget();
				return basicGetTarget();
			case IotaPackage.INCLUSION__ARGUMENTS:
				return getArguments();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case IotaPackage.INCLUSION__TARGET:
				setTarget((Property)newValue);
				return;
			case IotaPackage.INCLUSION__ARGUMENTS:
				getArguments().clear();
				getArguments().addAll((Collection<? extends Variable>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case IotaPackage.INCLUSION__TARGET:
				setTarget((Property)null);
				return;
			case IotaPackage.INCLUSION__ARGUMENTS:
				getArguments().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case IotaPackage.INCLUSION__TARGET:
				return target != null;
			case IotaPackage.INCLUSION__ARGUMENTS:
				return arguments != null && !arguments.isEmpty();
		}
		return super.eIsSet(featureID);
	}

}
